<template>
	<view class="page">
		<image :src="storeInfo.logo_img" mode=""></image>
		<view class="markAddress">
			<view class="title1">
				<view class="title1Item1">
					{{storeInfo.store_name}}
				</view>
				<view class="title1Item2" @click="savePaySort">
					帮他靠前
				</view>
			</view>
			
			<view class="introduction">
				<view class="">
					{{storeInfo.introduce}}
				</view>
				<view class="more">
					>
				</view>
			</view>
			<view class="phone">
				<view class="">
					服务电话: {{storeInfo.phone}}
				</view>
				<view class="phone1" >
					一件拨打>
				</view>
			</view>
			
			
			<view class="total">

				<view class="title" @click="viewsIdx = 1">
					<view class="totalItem"></view>
					
					<text>拍卖活动</text>
					
				</view>
				
				<view class="title"  @click="viewsIdx = 2">
					<view class="totalItem"></view>
					
					<text>拍卖许可证</text>
					
				</view>
				<view class="title"  @click="viewsIdx = 3">
					<view class="totalItem"></view>
					
					<text>拍卖师资格证</text>
					
				</view>
				
			</view>
			<view class="" v-if="viewsIdx == 2">
				<view class="">
					<image v-for="(el,idx) in storeInfo.licence_img_list" :src="el" mode=""  :key="idx"></image>
				</view>
				
			</view>
			<view class="" v-if="viewsIdx == 3">
			
				<view class="">
					<image v-for="(el,idx) in storeInfo.nvq_img_list" :src="el" mode=""  :key="idx"></image>
				</view>
			</view>
			<view class="" v-if="viewsIdx == 1">
				
				<view class="">
					<u-list>
						<u-list-item v-for="(item, index) in goodsList" :key="index">
							<view
								style="height: 200rpx;background-color:#fff;margin:10upx 40upx 10upx;padding: 20upx;border-radius: 3%;"
								@click="goXiangqing(item)">
								<u-row customStyle="height:100%">
									<u-col span="4">
										<view class="" style="height: 100%;">
											<u-image
												:src="item.title_img"
												width="200rpx" height="160rpx"></u-image>
										</view>
									</u-col>
									<u-col span="8" align="center">
										<u-row customStyle="margin-bottom:10px">
											<view class="">
												{{item.title}}
											</view>
										</u-row>
										<u-row>
											<view class="">
												{{item.ctime}}
											</view>
										</u-row>
									</u-col>
								</u-row>
							</view>
						</u-list-item>
					</u-list>
				</view>
			</view>
		
			



		</view>
		
		<u-popup :show="goodsBox" mode="center">
			<view class="popup-content">
				<u--form labelPosition="left"  ref="uForm">
					<u-form-item>
						<template #label class="title">
							<span style="color: red;">*</span>
							<span style="margin-bottom: 120rpx;font-weight: bold;">视频文件:</span>
						</template>
					
					</u-form-item>
					<u-form-item prop="userInfo.video" borderBottom>
						<u-upload :fileList="fileList2" @afterRead="afterRead" @delete="deletePic" name="2" multiple
							:maxCount="1" accept="video"></u-upload>
					</u-form-item>
					<u-form-item>
						<template #label class="title">
							<span style="color: red;">*</span>
							<span style="margin-bottom: 120rpx;font-weight: bold;">商品图册:</span>
						</template>
					
					</u-form-item>
					<u-form-item borderBottom>
						<u-upload :fileList="fileList3" @afterRead="afterRead" @delete="deletePic" name="3" multiple
							:maxCount="10" :previewFullImage="true"></u-upload>
					</u-form-item>
					<u-form-item>
						<template #label class="title">
							<span style="color: red;">*</span>
							<span style="font-weight: bold;">商品详情:</span>
						</template>
					</u-form-item>
					<uni-forms-item prop="userInfo.firm" borderBottom>
						<u--textarea v-model="goodsdetailsTxt" placeholder="建议描述商品细节等" height="80" maxlength="150" count="true"
							border="bottom"></u--textarea>
					</uni-forms-item>
					
				</u--form>
				<view class="button-group">
					<view class="item item1" @click="submit" type="primary">提交</view>
					<view class="item item2" @click="goodsBox = false">取消</view>
				</view>
			</view>
		</u-popup>
		<!-- 弹框 -->

		<u-popup :show="showPaymentDialog" mode="center">
			<view class="popup-content">

				<image style="width: 200rpx;height: 200rpx;"
					src="http://140.143.146.33/wxImg/static/wx_pay.png" mode="">
				</image>

				<view class="popup-title">发到手机微信支付</view>
				<view class="popup-description">请确认支付金额</view>
				<view class="popup-amount">金额：{{ amount }} 元</view>
				<view class="payment" @click="initiatePayment">二维码支付</view>
				<view class="cancel" @click="closeDialog">取消</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import {
		uploadImg,
		orderAppariser,
		uploadVideo,
		addViews,
		getAdActivity,
		getAppraiserInfo,
		savePaySort,
		delNameById,
		getLSpaySort
		
	} from '@/config/api.js';
	export default {
		data() {
			return {
				viewsIdx: 1,
				goodsdetailsTxt: '',
				fileList2:[],
				fileList3:[],
				goodsBox: false,
				queryList:{
					navId: null,
					markId: null,
					storeId: null,
					status: 1,
					page: 1,
					limit: 20
				},
				showPaymentDialog: false, // 控制弹框显示
				amount: 100, // 支付金额，可以根据需要进行动态设置
				storeInfo: {},
				goodsList: [],
			}
		},
		onLoad(options) {
			console.log(options,'=======')
			uni.setStorageSync('adInfo','')
			// 获取传递的标题
			if (options.title) {
				this.title = decodeURIComponent(options.title); // 解码并设置标题
				uni.setNavigationBarTitle({
					title: this.title // 设置导航栏标题
				});
				this.queryList.navId = options.navId;
				this.queryList.storeId = options.storeId;
				this.getListGoods();
				this.getList();
				addViews({id: options.storeId, nav_id: options.navId}).then()
			}
		},
		methods: {
			savePaySort(){
				const _this = this;
				uni.showModal({
					title: '确认付费提升排名？',
					success: function(res) {
						if (res.confirm) {
							getLSpaySort({
								nav_id: _this.queryList.navId
							}).then(data => {
								if(data.signType){
									wx.requestPayment({
									  timeStamp: data.timeStamp,
									  nonceStr: data.nonceStr,
									  package: data.package,
									  signType: data.signType,
									  paySign: data.paySign,
									  success (res) { 
										  savePaySort({
											  store_id: _this.queryList.storeId,
											  nav_id: _this.queryList.navId
										  }).then(res => {
											  console.log(res,'=============')
											  uni.$u.toast('操作成功!')
										  })
									  },
									  fail (res) { 
										  // 支付失败 删除商品
										  delNameById({order_sn: data._order_sn})
									  }
									})
								}
							})
						}
					}
				});
			},
			getList(){
				getAdActivity(this.queryList).then(res=>{
					this.goodsList = res.data;
				})
			},
			submit(){
				const sendata = {
					nav_id:this.queryList.navId,
					goods_video_url : this.fileList2[0]['url'],
					goods_details_txt:this.goodsdetailsTxt,
					store_id:this.queryList.storeId,
					appraiser_fee: this.storeInfo.appraiser_fee
				}
				const imgList = [];
				this.fileList3.forEach(el => {
					imgList.push(el.url)
				});
				sendata['img_list'] = imgList.join();
				orderAppariser(sendata).then(res => {
					uni.$u.toast('操作成功!')
					this.goodsBox = false;
				})
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					let result = null;
					if (lists[i].type == 'video') result = await this.uploadFileVideoe(lists[i].url);
					if (lists[i].type == "image") result = await this.uploadFilePromise(lists[i].url);
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},
			uploadFileVideoe(url) {
				return new Promise((resolve, reject) => {
					uploadVideo({
						url: url,
						fileName: 'appraiserOrder'
					}).then(res => {
						resolve(res)
					})
				})
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					uploadImg({
						url: url,
						fileName: 'appraiserOrder'
					}).then(res => {
						resolve(res)
					})
				})
			},
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			gotoGoods(item){
				uni.navigateTo({
					url: `/moduleB/GoodsDetails/GoodsDetails?title=${encodeURIComponent(item.title+'详情')}&goodsId=${item.id}`,
				});
			},
			getListGoods(){
				getAppraiserInfo(this.queryList).then(res => {
					// this.goodsList = res.data;
					this.storeInfo = res
				})
			},
			//微信支付
			openPaymentDialog() {
				console.log('888888');
				this.showPaymentDialog = true; // 显示支付弹框
			},
			closeDialog() {
				this.showPaymentDialog = false; // 关闭支付弹框
			},
			goXiangqing(data) {
				uni.setStorageSync('adInfo',data)
				uni.navigateTo({
					url: '/moduleA/guanggaoxiangqing/paimaixiangqing'
				})
			},
			initiatePayment() {
				// 调用微信支付接口，假设你的后端返回了需要的支付参数
				const paymentData = {
					timeStamp: '1234567890', // 时间戳
					nonceStr: 'abc123', // 随机字符串
					package: 'prepay_id=wx1234567890', // 预支付交易会话标识
					signType: 'MD5', // 签名方式
					paySign: 'abcdefg1234567', // 签名
				};

				uni.requestPayment({
					...paymentData,
					success: (res) => {
						uni.showToast({
							title: '支付成功',
							icon: 'success',
						});
						this.closeDialog(); // 关闭弹框
					},
					fail: (err) => {
						uni.showToast({
							title: '支付失败',
							icon: 'none',
						});
						console.error(err);
					},
				});
			},

		}
	}
</script>


<style scoped lang="scss">
	@import 'markAddress.scss';

	.popup-content {
		padding: 20px;
		text-align: center;
	}

	.popup-title {
		font-size: 18px;
		font-weight: bold;
	}

	.popup-description {
		margin: 10px 0;
	}

	.popup-amount {
		font-size: 16px;
		color: #333;
		margin-bottom: 20px;
	}

	.payment {
		width: 500rpx;
		height: 80rpx;
		line-height: 80rpx;
		color: #fff;
		background-color: springgreen;
	}

	.cancel {
		width: 500rpx;
		height: 80rpx;
		line-height: 80rpx;

	}
</style>